
import java.util.Arrays;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

	public static void main(String[] args) {
		// Scanner sc = new Scanner(System.in);
		// while(sc.hasNext()) {
		// String s = sc.nextLine().replaceAll("\"", "").replaceAll("\\s+", " ");
		// System.out.println(s);
		// }
		// sc.close();

		// String s = "combine 1234567890 abcdefgh 1234567890";
		// int idx = s.indexOf(" ");
		// System.out.println(s.substring(idx+1));

		// String s = "\"12 34567890\" \"ab cdefgh\" \"1234 567890\"";
		// Matcher m = Pattern.compile("\\\"[^\\\"]*\\\"").matcher(s);
		// while (m.find()) {
		// System.out.println(m.group().replaceAll("\"", ""));
		// }

		// String s = "\"12 34567890\" \"ab cdefgh\" \"1234 567890\"";
		// String s = "1234 567890";
		// String[] a = s.split("\"\\s{1}\"");
		// for (int i = 0; i < a.length; i++) {
		// System.out.println(a[i].replaceAll("\"", ""));
		// }

		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			String s = sc.nextLine();
			System.out.println(calc(s));
		}
		sc.close();

	}

	private static String calc(String s) {

		StringBuilder sb = new StringBuilder();
		int idx = s.indexOf(" ");
		String oper = s.substring(0, idx);
		String[] a = s.substring(idx + 1).split("\"\\s{1}\"");
		for (int i = 0; i < a.length; i++) {
			a[i]=a[i].replaceAll("\"", "");
		}
		System.out.println(Arrays.toString(a));
		if (oper.equals("combine")) {
			sb.delete(0, sb.length());
			for (int i = 0; i < a.length; i++) {
				sb.append(a[i]);
			}
		} else if (oper.equals("search")) {
			sb.delete(0, sb.length());
			int idx1 = a[0].indexOf(a[1]);
			if (idx1 == -1) {
				sb.append("");
			} else {
				sb.append(a[0].substring(idx1));
			}
		} else if (oper.equals("reverse")) {
			sb.delete(0, sb.length());
			for (int i = 0; i < a.length; i++) {
				sb.append(a[i]);
			}
			String tmp = sb.reverse().toString();
			sb.delete(0, sb.length());
			sb.append(tmp);
		} else if (oper.equals("quote")) {
			sb.delete(0, sb.length());
			for (int i = 0; i < a.length; i++) {
				sb.append(a[i]);
			}
		}
		return sb.toString();
	}

}
